<?php
if (!defined("LEVEL") || LEVEL < 30 || !defined("OK")) { header('location: ?home'); }
if (isset($_POST['a_pro_create']) && $_POST['a_pro_create'] == 'Sukurti') {
	$pav = $_POST['a_pro_pav'];
	if (isset($_POST['a_pro_show'])) { $rodoma = "TAIP"; }
	else { $rodoma = "NE"; }
	$link = $_POST['a_pro_link'];
	$db->uzklausa("INSERT INTO projektai (pav, page, rodyti) VALUES (
					" . escape($pav) .",
					" . escape($link) .",
					" . escape($rodoma) .")") or die(mysql_error());
	header("Location: ?id,46;a,7");
}

if (isset($_POST['a_pro_del']) && $_POST['a_pro_del'] == 'Trinti') {
	if (isset($_POST['projects']) && isnum($_POST['projects']) && $_POST['projects'] > 0) { 
		$db->uzklausa("DELETE FROM `projektai` WHERE `projektai`.`id` = ".escape((int)$_POST['projects'])." LIMIT 1");
	}
	else { klaida("Klaida","Prasome patikrinti info"); header("Location: ?id,46;a,7","meta"); }
}

$sql = $db->uzklausa("SELECT * FROM projektai");
echo "
	<table>
		<tr>
			<td valign='top'>";
				$text = "
				<form name=\"admin_pro_show\" action=\"\" method=\"post\">
					<select size=\"1\" name=\"projects\">";
						while ($row = mysql_fetch_assoc($sql)) {
							$text .= "<option value=" . $row['id'] .">" . $row['pav'] ."</option>";
						}
				$text .= "
					</select>
					<input name=\"a_pro_edit\" type=\"submit\" value=\"Redaguoti\">
					<input name=\"a_pro_del\" type=\"submit\" value=\"Trinti\">
				";
				lentele("NightVision Projektai",$text);
				unset($text);
			echo "
			</td>
			<td valign='top'>
			";
				$text = "
					<form name=\"admin_pro_create\" action=\"\" method=\"post\">
					<table>
						<tr>
							<td>Pavadinimas</td>
							<td></td>
							<td><input name=\"a_pro_pav\" style=\"width:100%\" type=\"text\" value=\"\"></td>
						</tr>
						<tr>
							<td>Nuoroda</td>
							<td><b>puslapiai/projektai/</b></td>
							<td><input name=\"a_pro_link\" style=\"width:100%\" type=\"text\" value=\"\"><b>.php</b></td>
						</tr>
						<tr>
							<td colspan='2'><input name=\"a_pro_show\" type=\"checkbox\" checked> Rodoma visiems</td>
							<td><input name=\"a_pro_create\" type=\"submit\" value=\"Sukurti\"></td>
						</tr>
					</table>
					</form>
				";
				lentele("Naujas NightVision Projektas",$text);
		echo "
		</tr>
	</table>
";

unset($sql, $text, $text);

?>